package com.aerfafish.spider.neo4j.repository;

import com.aerfafish.spider.neo4j.dao.Share;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author aerfafish
 * @date 2021/4/21 9:42 上午
 */
@Component
public interface ShareRepository extends Neo4jRepository<Share, Long> {

    @Query("match (share:Share{shareCode:$shareCode} return share)")
    List<Share> queryByShareCode(@Param("shareCode") String shareCode);

    @Query("merge (share:Share{code:$code}) set share.marketNum=$marketNum, share.market=$market, " +
            "share.shareName=$shareName, share.latestValue=$latestValue, share.incRate=$incRate")
    void save (@Param("code") String code,
               @Param("marketNum") Integer marketNum,
               @Param("market") String market,
               @Param("shareName") String shareName,
               @Param("latestValue") Float latestValue,
               @Param("incRate") Float incRate);

    @Query("match (share:Share) return share.market + share.code")
    List<String> queryAllShareByCode();
}
